var obj1 = {
    a: 1,
    b: {
        c: 2,
        d: 3
    },
    e: 4,
    h: {
        i: 5
    }
}
var obj2 = {
    a: 111,
    b: {
        c: 222,
        f: 333
    },
    g: 444,
    h: 666
}
// 实现一个mergeObject(obj1, obj2)方法，得到下面的对象，并转化成JSON输出到#app
var obj = {
    a: 111,
    b: {
        c: 222,
        d: 3,
        f: 333
    },
    e: 4,
    g: 444,
    h: 666
}
//? obj2覆盖obj1
function mergeObject(obj1, obj2) {

    for (let i in obj2) {
        let t1 = obj1[i] instanceof Object
        let t2 = obj2[i] instanceof Object
        //? 都是Object
        if (t1 && t2) {
            mergeObject(obj1[i], obj2[i])
        }
        //? 是非Object 直接覆盖了
        else {
            obj1[i] = obj2[i]
        }
    }
    return obj1
}

console.log(mergeObject(obj1, obj2));
